package com.colorfruit.admin.control.controller;

import com.colorfruit.admin.business.service.OrderService;
import com.colorfruit.framework.model.pojo.BaseResult;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    HttpServletRequest request;

    /**
     * 查询未支付订单列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectNotPayOrderList")
    public BaseResult selectNotPayOrderList(int page, int size){
        String userId = request.getHeader("userId");
        log.info("# [IN] [controller] selectNotPayOrderList param: userId = {}, page = {}, size = {}", userId, page, size);
        PageInfo pageInfo = orderService.selectNotPayOrderList(userId, page, size);
        log.info("# [OUT] [controller] selectNotPayOrderList SUCCESS");
        return new BaseResult(pageInfo);
    }

    /**
     * 查询代发货列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectNotTransportOrderList")
    public BaseResult selectNotTransportOrderList(int page, int size){
        String userId = request.getHeader("userId");
        log.info("# [IN] [controller] selectNotTransportOrderList param: userId = {}, page = {}, size = {}", userId, page, size);
        PageInfo pageInfo = orderService.selectNotTransportOrderList(userId, page, size);
        log.info("# [OUT] [controller] selectNotTransportOrderList SUCCESS");
        return new BaseResult(pageInfo);
    }

    /**
     * 查询代签收列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectNotSignOrderList")
    public BaseResult selectNotSignOrderList(int page, int size){
        String userId = request.getHeader("userId");
        log.info("# [IN] [controller] selectNotSignOrderList param: userId = {}, page = {}, size = {}", userId, page, size);
        PageInfo pageInfo = orderService.selectNotSignOrderList(userId, page, size);
        log.info("# [OUT] [controller] selectNotSignOrderList SUCCESS");
        return new BaseResult(pageInfo);
    }

    /**
     * 查询已签收列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectSignedOrderList")
    public BaseResult selectSignedOrderList(int page, int size){
        String userId = request.getHeader("userId");
        log.info("# [IN] [controller] selectSignedOrderList param: userId = {}, page = {}, size = {}", userId, page, size);
        PageInfo pageInfo = orderService.selectSignedOrderList(userId, page, size);
        log.info("# [OUT] [controller] selectSignedOrderList SUCCESS");
        return new BaseResult(pageInfo);
    }

    /**
     * 取消订单
     * @param businessNo
     * @return
     */
    @GetMapping("/cancelOrder")
    public BaseResult cancelOrder(String businessNo){
        String userId = request.getHeader("userId");
        log.info("# [IN] [controller] cancelOrder param: businessNo = {}, userId = {}", businessNo, userId);
        BaseResult baseResult = orderService.cancelOrder(businessNo, userId);
        log.info("# [OUT] [controller] cancelOrder SUCCESS");
        return baseResult;
    }

    /**
     * 确认收货
     * @param businessNo
     * @return
     */
    @GetMapping("/confirmReceiveProduct")
    public BaseResult confirmReceiveProduct(String businessNo){
        log.info("# [IN] [controller] confirmReceiveProduct param: businessNo = {}", businessNo);
        String userId = request.getHeader("userId");
        BaseResult baseResult = orderService.confirmReceiveProduct(userId, businessNo);
        log.info("# [OUT] [controller] confirmReceiveProduct SUCCESS");
        return baseResult;
    }

    /**
     * 查询物流信息
     * @param businessNo
     * @return
     */
    @GetMapping("/searchLogicInfo")
    public BaseResult searchLogicInfo(String businessNo){
        log.info("# [IN] [controller] searchLogicInfo param: businessNo = {}", businessNo);
        BaseResult baseResult = orderService.searchLogicInfo(businessNo);
        log.info("# [OUT] [controller] searchLogicInfo SUCCESS");
        return baseResult;
    }

    /**
     * 查询交易信息
     * @param businessNo
     * @return
     */
    @GetMapping("/searchTradeInfo")
    public BaseResult searchTradeInfo(String businessNo){
        log.info("# [IN] [controller] searchTradeInfo param: businessNo = {}", businessNo);
        BaseResult baseResult = orderService.searchTradeInfo(businessNo);
        log.info("# [OUT] [controller] searchTradeInfo SUCCESS");
        return baseResult;
    }

}
